package com.bindapp.activity;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.view.View;

import com.bindapp.App;
import com.bindapp.R;
import com.bindapp.databinding.ActivityTextBinding;
import com.bindapp.util.ezutil.EZUtils;
import com.videogo.constant.IntentConsts;
import com.videogo.exception.BaseException;
import com.videogo.openapi.bean.EZCameraInfo;
import com.videogo.openapi.bean.EZDeviceInfo;

import java.util.ArrayList;
import java.util.List;

import static com.bindapp.App.getOpenSDK;

/**
 * Created by apple on 2018/7/10.
 */

public class Text2Activity extends BaseActivity {
    private ActivityTextBinding binding;
    private List<EZDeviceInfo> mlist=new ArrayList<EZDeviceInfo>();



    @Override
    protected void after() {
        super.after();
        String token = "ra.8lnj7mk0b9bdaw7qbhotu0671d82cikf-2o902bh0wy-1coly49-99vbnay0b";

        App.getOpenSDK().setAccessToken(token);
        binding= DataBindingUtil.setContentView(this, R.layout.activity_text);
        binding.submit.setOnClickListener(new ViewClick());
        binding.livebtn.setOnClickListener(new ViewClick());
        initData();
    }

    private void initData(){
        new Thread(){
            @Override
            public void run() {
                try {
                    mlist.clear();
                    mlist.addAll(getOpenSDK().getDeviceList(0, 20));

                } catch (BaseException e) {
                    e.printStackTrace();
                }
            }
        }.start();

    }


    class ViewClick implements View.OnClickListener{

        @Override
        public void onClick(View view) {
            switch(view.getId()){
                case R.id.livebtn:

                    break;
                case R.id.submit:
                    if(mlist.size()>0){
                        EZDeviceInfo deviceInfo=mlist.get(0);
                        EZCameraInfo cameraInfo = EZUtils.getCameraInfoFromDevice(deviceInfo, 0);
                        Intent intent=new Intent(Text2Activity.this,DevicePlayActivity.class);
                        intent.putExtra(IntentConsts.EXTRA_DEVICE_INFO, deviceInfo);
                        intent.putExtra(IntentConsts.EXTRA_CAMERA_INFO, cameraInfo);
                        startActivity(intent);
                    }
                    break;
            }


        }
    }
}
